package dao

import (
	"go-project/common"
	"go-project/common/base"
	"go-project/internal/model"
)

type userDao struct {
	base.Dao[model.User]
}

var UserDao = new(userDao)

//func (d *userDao) Page(query *model.UserDto) ([]*model.User, int64, error) {
//	var list []*model.User
//	tx := common.DB.Model(model.User{})
//	if query.Name != nil && len(*query.Name) > 0 {
//		tx.Where("name like ?", "%"+*query.Name+"%")
//	}
//	count, err := utils.Page(tx, &list, &query.Pager)
//	return list, count, err
//}

func (d *userDao) FindByUsername(username string) (*model.User, error) {
	user := new(model.User)
	tx := common.DB.Model(model.User{})
	err := tx.Where("username = ?", username).First(user).Error
	return user, err
}
